home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / SpriteWorld 2.2 / SpriteWorld Examples / Shark Attack / Sources & Headers / Special Effects.c < prev    next >
Encoding:
Text File  |  1999-01-22  |  2.9 KB  |  102 lines  |  [TEXT/CWIE]

  1. ///--------------------------------------------------------------------------------------
  2. // Special Effects.c
  3. ///--------------------------------------------------------------------------------------
  4.  
  5. #include "Special Effects.h"
  6. #include "Timer.h"
  7.  
  8. #define kWipeSpeed    1        // Number of microseconds between each line of the wipe
  9.  
  10.  
  11. ///--------------------------------------------------------------------------------------
  12. //  WipeWindow
  13. ///--------------------------------------------------------------------------------------
  14.  
  15. void    WipeWindow(SpriteWorldPtr spriteWorldP)
  16. {
  17.     short        topRow, bottomRow;
  18.     Rect        sourceRect, destRect;
  19.     GrafPtr        savePort;
  20.     
  21.     GetPort(&savePort);
  22.     SWSetPortToWindow(spriteWorldP);
  23.     
  24.         // Position topRow and bottomRow in the middle of the screen
  25.     bottomRow = spriteWorldP->windRect.bottom - spriteWorldP->windRect.top;
  26.     for (topRow = 0; topRow <= bottomRow; topRow++, bottomRow--)
  27.         NULL;
  28.     
  29.     sourceRect.left = spriteWorldP->visScrollRect.left;
  30.     sourceRect.right = spriteWorldP->visScrollRect.right;
  31.     destRect.left = sourceRect.left + spriteWorldP->windRect.left;
  32.     destRect.right = sourceRect.right + spriteWorldP->windRect.left;
  33.     
  34.     while (topRow >= 0)
  35.     {
  36.         StartMicrosecTimer();
  37.         
  38.         topRow--;
  39.         bottomRow++;
  40.         
  41.         sourceRect.top = topRow;
  42.         sourceRect.bottom = topRow+1;
  43.         destRect.top = topRow + spriteWorldP->windRect.top;
  44.         destRect.bottom = destRect.top+1;
  45.         
  46.         (*spriteWorldP->screenDrawProc)(spriteWorldP->workFrameP,
  47.                 spriteWorldP->windowFrameP, &sourceRect, &destRect);
  48.         
  49.         sourceRect.top = bottomRow;
  50.         sourceRect.bottom = bottomRow+1;
  51.         destRect.top = bottomRow + spriteWorldP->windRect.top;
  52.         destRect.bottom = destRect.top+1;
  53.         
  54.         (*spriteWorldP->screenDrawProc)(spriteWorldP->workFrameP,
  55.                 spriteWorldP->windowFrameP, &sourceRect, &destRect);
  56.         
  57.         WaitMicroseconds(kWipeSpeed);
  58.     }
  59.     
  60.     SetPort(savePort);
  61. }
  62.  
  63.  
  64. UnsignedWide     lastMicroseconds,    // Value of previous Microseconds() call
  65.                 curMicroseconds;    // Value of current Microseconds() call
  66. unsigned long    millisecDifference;    // Difference between the two values
  67.  
  68.  
  69. ///--------------------------------------------------------------------------------------
  70. //  StartMicrosecTimer - call this, then WaitMicroseconds
  71. ///--------------------------------------------------------------------------------------
  72.  
  73. void    StartMicrosecTimer( void )
  74. {
  75.     Microseconds(&lastMicroseconds);
  76. }
  77.  
  78.  
  79. ///--------------------------------------------------------------------------------------
  80. //  WaitMicroseconds
  81. ///--------------------------------------------------------------------------------------
  82.  
  83. void    WaitMicroseconds(unsigned long delay)
  84. {
  85.     do
  86.     {
  87.         Microseconds(&curMicroseconds);
  88.         
  89.             // Has hi long has rolled over?
  90.         if (curMicroseconds.hi > lastMicroseconds.hi)
  91.         {
  92.             millisecDifference =  
  93.                 (0xffffffff - (lastMicroseconds.lo - curMicroseconds.lo))/1000;
  94.         }
  95.         else
  96.         {
  97.             millisecDifference = (curMicroseconds.lo - lastMicroseconds.lo)/1000;
  98.         }
  99.     } while (millisecDifference < delay);
  100. }
  101.  
  102.